
<template>
    <div class="resource-manage">
        <div class="card-box">
            <div class="card-title">
                <span>物业权属</span>
                <el-button-group v-show="false">
                    <el-button :disabled="!isAdd" v-for="item in propertyOwnerships" :key="item.value" size="small" :type="propertyOwnership == item.value?'primary':'default'" @click="selectOwner(item.value, item.label)">{{item.label}}</el-button>
                </el-button-group>
            </div>
            <div class="card-box">
                <div class="card-title">
                    <span>{{labelName}}</span>
                </div>
                <div>
                    <el-form v-if="propertyOwnership == '10'" ref="propertyForm" :model="propertyForm" class="form-wrap" size="small" >
                        请在不动产登记模块完善该关联关系
                        <!--<el-form-item  label="产权证编号" prop="cardNum" :rules="propertyForm_rules.cardNum">
                            <el-input :disabled="!isAdd" v-model="propertyForm.cardNum" placeholder="请输入产权证编号"></el-input>
                        </el-form-item>
                        <el-form-item label="登记价格" prop="propertyPrice"  :rules="propertyForm_rules.propertyPrice">
                            <el-input :disabled="!isAdd" v-model="propertyForm.propertyPrice" placeholder="请输入登记价格"></el-input>
                        </el-form-item>
                        <el-form-item label="产权人" prop="obligee"  :rules="propertyForm_rules.obligee">
                            <el-input :disabled="!isAdd" v-model="propertyForm.obligee" placeholder="请输入产权人"></el-input>
                        </el-form-item>
                        <el-form-item label="产权类型" prop="cardType" :rules="propertyForm_rules.cardType">
                            <el-select :disabled="!isAdd"  v-model="propertyForm.cardType" placeholder="请选择产权类型">
                                <el-option
                                    v-for="item in proprietaryTypes"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="产权使用期限" prop="serviceLife" :rules="propertyForm_rules.useTimeDate">
                            <el-date-picker
                                :disabled="!isAdd"
                                v-model="propertyForm.serviceLife"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="产权年限" prop="useTime" :rules="propertyForm_rules.useTime">
                            <el-input-number  :disabled="!isAdd" style="width: auto"  v-model="propertyForm.useTime" controls-position="right" :min="0" :step="10" :max="70"></el-input-number>
                        </el-form-item>-->
                    </el-form>
                    <el-form v-else ref="borrowForm" :model="borrowForm" class="form-wrap" size="small" >
                        <el-form-item label="物业归属方" v-if="propertyOwnership == '20' || propertyOwnership == '30' || propertyOwnership == '40' " prop="propertyBelong" :rules="borrowForm_rules.propertyBelong">
                            <el-input maxlength="50" v-model="borrowForm.propertyBelong" placeholder="请输入物业归属方"></el-input>
                        </el-form-item>
                        <el-form-item label="当前管理人" v-if="propertyOwnership == '20' || propertyOwnership == '30' || propertyOwnership == '40' " prop="currentManager"  :rules="borrowForm_rules.currentManager">
                            <el-input maxlength="50"  v-model="borrowForm.currentManager" placeholder="请输入当前管理人"></el-input>
                        </el-form-item>
                        <el-form-item label="无产权原因" v-if="propertyOwnership == '40' " prop="propertyReason"  :rules="borrowForm_rules.propertyReason">
                            <el-input maxlength="100"  v-model="borrowForm.propertyReason" placeholder="请输入无产权原因"></el-input>
                        </el-form-item>
                        <el-form-item label="其他权属证明" v-if="propertyOwnership == '50' " prop="propertyCertificate"  :rules="borrowForm_rules.propertyCertificate">
                            <el-input maxlength="100"  v-model="borrowForm.propertyCertificate" placeholder="请输入其他权属证明"></el-input>
                        </el-form-item>
                        <el-form-item label="其他权属年限" v-if="propertyOwnership == '50' " prop="propertyYear"  :rules="borrowForm_rules.propertyYear">
                            <el-input-number style="width: auto"  v-model="borrowForm.propertyYear" controls-position="right" :min="0" :step="10" :max="70"></el-input-number>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import { getDict } from '~/utils'
    import { doubleValidate} from '~/utils/validate.js'

    export default {
        name: "property-ownership",
        data() {
            return {
                labelName: '',
                propertyOwnership: '',
                input: '',
                value: '',
                propertyForm: {
                    cardNum: '',
                    propertyPrice: '',
                    obligee: '',
                    cardType: '',
                    useTimeDate: '',
                    useTime: ''
                },
                propertyForm_rules: {
                    cardNum: [
                        { required: true, message: "请输入产权证编号", trigger: "blur" },
                    ],
                    propertyPrice: [
                        { required: true, message: "请输入登记价格", trigger: "blur" },
                        { validator: doubleValidate, trigger: "change"},
                    ],
                    obligee: [
                        { required: true, message: "请输入产权人", trigger: "blur" },
                    ],
                    cardType: [
                        { required: true, message: "请选择产权类型", trigger: "blur" },
                    ],
                    serviceLife: [
                        { required: true, message: "请选择产权使用期限", trigger: "blur" },
                    ],
                    useTime: [
                        { required: true, message: "请输入产权年限", trigger: "blur" },
                        { type: 'number', message: '产权年限必须为数字值'}
                    ]
                },
                borrowForm:{
                    propertyBelong: '',
                    currentManager: '',
                    propertyReason: '',
                    propertyCertificate: '',
                    propertyYear: ''
                },
                borrowForm_rules: {
                    propertyBelong: [
                        { required: true, message: "请输入物业归属", trigger: "blur" },
                    ],
                    currentManager: [
                        { required: true, message: "请输入当前管理人", trigger: "blur" },
                    ],
                    propertyReason: [
                        { required: true, message: "请输入无产权原因", trigger: "blur" },
                    ],
                    propertyCertificate: [
                        { required: true, message: "请输入其他权属证明", trigger: "blur" }
                    ],
                    propertyYear: [
                        { required: true, message: "请输入其他权属年限", trigger: "blur" },
                        { type: 'number', message: "请输入0-70的整数", trigger: "blur" , min: 0, max: 70 },
                    ]
                },
                propertyOwnerships: [],
                proprietaryTypes: [],
                isAdd: true
            }
        },
        created() {
            this.propertyOwnerships = getDict('property_ownerships')
            this.proprietaryTypes = getDict('proprietary_types')
            //初始化值
            if(!this.labelName){
                this.labelName = '政府产权'
                this.propertyOwnership = '10'
            }
        },
        methods: {
            selectOwner(val, label) {
                let pf = this.$refs['propertyForm'];
                if(pf){
                    pf.resetFields()
                }
                let bf = this.$refs['borrowForm'];
                if(bf){
                    bf.resetFields()
                }
                this.propertyOwnership = val
                this.labelName = label
            },
            initOwner(propertyInfo, propertyCard, propertyOwnership){
                this.isAdd = false
                if(propertyInfo){
                    this.borrowForm = propertyInfo
                }
                if(propertyCard){
                    console.log(propertyCard)
                    let pform = {
                        cardNum: propertyCard.cardNum,
                        propertyPrice: propertyCard.propertyPrice,
                        obligee: propertyCard.obligee,
                        cardType: propertyCard.cardType,
                        serviceLife: propertyCard.serviceLife,
                        useTime: propertyCard.useTime
                    }
                    this.propertyForm = pform
                }
                this.propertyOwnership = propertyOwnership
            }
        }
    }
</script>

<style scoped lang='scss'>


    @include formWrap(2);

</style>
